import java.io.*;
import java.net.*;

public class FirstServer {
	public static void main(String[] args) {
		ServerSocket server = null;
		try {
			server = new ServerSocket(1234);
		} catch (IOException ex) {
			System.out.println("There is already a server in the port");
		}

		Socket connect = null;
		while (true) {
			try {
				connect = server.accept();
				InputStreamReader in
					= new InputStreamReader(connect.getInputStream());
				int c;
				while ( (c=in.read()) != -1) 
					System.out.write(c);

				connect.close();
			} catch (IOException ex) {
			} finally {
				try{
					if (connect!=null) 
						connect.close();
				} catch (IOException e) { }
			}
		}
	}
}
